/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package PD.data.parser.impl;

import PD.data.Row;
import PD.data.impl.peaklists.SimpleNodeRow;
import PD.data.parser.Parser;
import com.csvreader.CsvReader;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author scsandra
 */
public class NodesFilesParser implements Parser {

        private String datasetPath;
        private int rowsNumber;
        private int rowsReaded;
        List<Row> dataset;

        public NodesFilesParser(String datasetPath) {
                if (datasetPath != null) {
                        this.rowsNumber = 0;
                        this.rowsReaded = 0;
                        this.datasetPath = datasetPath;
                        this.dataset = new ArrayList<Row>();
                }
        }

        public float getProgress() {
                return (float) rowsReaded / rowsNumber;
        }

        public void fillData() {
                try {
                        CsvReader reader = new CsvReader(new FileReader(datasetPath));
                        reader.readHeaders();                      
                        while (reader.readRecord()) {
                                getData(reader.getValues());
                                rowsReaded++;
                        }

                } catch (Exception e) {
                        e.printStackTrace();
                }
        }

        private void getData(String[] sdata) {
                try {
                        Row lipid = new SimpleNodeRow();
                        try {
                                lipid.setID(Integer.valueOf(sdata[0]));                               
                                lipid.setWeight(Double.valueOf(sdata[1]));
                                lipid.setLowerBound(Integer.valueOf(sdata[2]));
                                lipid.setUpperBound(Integer.valueOf(sdata[3]));
                                lipid.setVertexType(sdata[4]);
                                lipid.setSWISSprotID(sdata[5]);
                                lipid.setKEGGCompoundID(sdata[6]);
                                lipid.setTransPathCompoundID(sdata[7]);
                        } catch (Exception e) {
                                e.printStackTrace();
                        }

                        this.dataset.add(lipid);

                } catch (Exception exception) {
                        exception.printStackTrace();
                }
        }

        public List<Row> getList() {
                return this.dataset;
        }
}
